// 登录业务
const formLogin = document.querySelector('.login-form')
const btnLogin = document.querySelector('#btn-login')
btnLogin.addEventListener('click', async function () {
  const data = serialize(formLogin, { hash: true, empty: true })
  // console.log(data)
  const { username, password } = data
  if (username.length < 8 || username.length > 30) {
    return showToast('请输入8~30位的账号')
  }
  if (password.length < 6 || password.length > 30) {
    return showToast('请输入6~30位的密码')
  }
  try {
    const  { data: { token }, message } = await axios.post('/login', data)
    // console.log(message)
    // console.log(token)
    showToast(message)
    //账号正确跳转页面
    localStorage.setItem('user', username)
    localStorage.setItem('token', token)
    location.href='index.html'
  } catch (err) {
    // console.dir(err)
  }
})